﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;


namespace WindowsFormsApplication3
{
   
    using Reports;
    using Reports.JobDetailsTableAdapters;
    using alldataset.fullldatasetTableAdapters;
    public partial class ConsolidationForm : Form
    {
        Transaction.CodeAutoGenerator cdgn = null;
        public ConsolidationForm()
        {
            InitializeComponent();
            cdgn = new Transaction.CodeAutoGenerator();
            lblconsolpk.Text = cdgn.NewConsolcodenoget();
        }

        private void Consolidationform_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'jobDetails.TblJobCode' table. You can move, or remove it, as needed.
            this.jobCodeTableAdapter.Fill(this.jobDetails.TblJobCode);
            // TODO: This line of code loads data into the 'nauferTransactionDemoDBDataSet1.drivermastertable' table. You can move, or remove it, as needed.
           
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbjobcode.SelectedValue != null)
            {
                getjobcodedetails(int.Parse(cmbjobcode.SelectedValue.ToString()));
            }
            else
            {
                MessageBox.Show("OK");
            }
        }


        public void getjobcodedetails(int jobpk )

        {

           
            jobcodemastertableTableAdapter adapt = new jobcodemastertableTableAdapter();
           
            adapt.Connection = new OleDbConnection(Program.ConnStr);
           
            DataTable dt = adapt.GetData(int .Parse(cmbjobcode.SelectedValue.ToString ()));

          if( dt.Rows.Count!=0){

              cmbcustmrcode.Text = dt.Rows[0][2].ToString();
              cmbcustmrcode.SelectedValue = int.Parse(dt.Rows[0][3].ToString());
              txtperson.Text = dt.Rows[0][4].ToString();
              txtnooftrip.Text = dt.Rows[0][5].ToString();
              rhtdescription.Text = dt.Rows[0][6].ToString();
              rhtfrom.Text = dt.Rows[0][7].ToString();
              rhtto.Text = dt.Rows[0][9].ToString();
              txtdate.Text = dt.Rows[0][8].ToString();
              rhtdescription.Enabled = false;
              rhtfrom.Enabled = false;
              rhtto.Enabled = false;
             

          }

           
        }

        private void txtcmpnyname(object sender, EventArgs e)
        {

        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {

           if (lblconsolpk.Text.Trim() == null || lblconsolpk.Text.Trim() == "")
           {
               MessageBox.Show("Consol code not generated>>  Transaction.CodeAutoGenerator()NewConsolcodenoget()");
               this.Close();
           }
           else
           {

               OleDbConnection oledbcon = new OleDbConnection(Program.ConnStr);
               oledbcon.Open();
               OleDbCommand cmd = new OleDbCommand("insert into consolidation_mastertable(jobpk ,customerpk,vehicleno,drivername,consolcode,nooftrip,consoldat,cntctperson )values(@pjobpk , @pcustomerpk, @pvehicleno, @pdrivername, @pconnsolcode, @pnooftrip, pconsoldate, @pcntctperson)", oledbcon);

               cmd.Parameters.AddWithValue("@pjobpk", cmbjobcode.SelectedValue);
               cmd.Parameters.AddWithValue(" @pcustomerpk", cmbjobcode.SelectedValue);
               cmd.Parameters.AddWithValue("@pvehicleno", txtvehicleno.Text);
               cmd.Parameters.AddWithValue(" @pdrivername", txtdrivernam.Text);
               cmd.Parameters.AddWithValue("@pconnsolcode", lblconsolpk.Text);
               cmd.Parameters.AddWithValue(" @pnooftrip", txtnooftrip.Text);
               cmd.Parameters.AddWithValue(" pconsoldate", txtdate.Text);
               cmd.Parameters.AddWithValue("  @pcntctperson", txtperson.Text);
               cmd.ExecuteNonQuery();
               MessageBox.Show("Sucess");



               oledbcon.Close();



           }
        }














































    }
}
